# Copyright (C) 2006  Apptility LLC  http://www.apptility.com
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

# TODO WE WILL MAP THIS TO STANDARD LOGGING API LATER like log4r or something else
module AjubyTools

   def self.exec_cmd(cmd, input=nil)
    if input
      return IO.popen(cmd, 'r+') {|io| io.puts input; io.close_write; io.read }
    else
      return IO.popen(cmd) {|io| io.read }
    end
  end

  def self.base64encode(rawstring)
    encoded   = Base64.encode64(rawstring)
  end
  
  def self.base64decode(encoded)
    decoded = Base64.decode64(encoded)
  end

  def self.hashed_salted_string(rawstring)  
    @salt = AuthenticatedUser.hashed("salt-#{Time.now}")
    AuthenticatedUser.salted_password(@salt, AuthenticatedUser.hashed(rawstring))
  end  

  def self.mask_string(rawstring, mask)  
    mask * rawstring.length
  end  

end